from launch import LaunchDescription
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument

def generate_launch_description():
    # 声明可配置的参数
    port_arg = DeclareLaunchArgument(
        'port',
        default_value='/dev/ttyUSB_US',
        description='串口设备路径'
    )
    
    baudrate_arg = DeclareLaunchArgument(
        'baudrate',
        default_value='9600',
        description='串口波特率'
    )
    
    frame_id_arg = DeclareLaunchArgument(
        'frame_id',
        default_value='laser',
        description='传感器坐标系ID'
    )
    
    # 创建节点
    ultrasonic_node = Node(
        package='ultrasonic_sensor',
        executable='ultrasonic_sensor_node',
        name='ultrasonic_sensor',
        output='screen',
        parameters=[
            {'port': LaunchConfiguration('port')},
            {'baudrate': LaunchConfiguration('baudrate')},
            {'frame_id': LaunchConfiguration('frame_id')}
        ],
        remappings=[
            # 可在此重映射话题名，例如:
            ('ultrasonic_distance', 'custom_distance_topic')
        ]
    )
    
    return LaunchDescription([
        port_arg,
        baudrate_arg,
        frame_id_arg,
        ultrasonic_node
    ])

